#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace PdfCreative.Pdf.Writer
{
    /// <summary>
    /// The PdfResourceParseException class is an exception that is thrown when a resource file cannot be parsed. The Writer throws this
    /// exception when a PDF document is being finalised. (which is when resources such as fonts and images are written
    /// to the PDF document stream)
    /// </summary>
    [Serializable]
    public class PdfResourceParseException : PdfException, ISerializable
    {
        // Private fields
        // ==============
        #region Private fields
        private PdfResourceReference _resource;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves a reference to the resource that could not be parsed.
        /// </summary>
        public PdfResourceReference Resource
        {
            get { return _resource; }
        }
        #endregion



        // Interface implementation
        // ========================
        #region ISerializable Members
        /// <summary>
        /// Stores this exception's properties into the serialisation stream.
        /// </summary>
        /// <param name="info">The serialisation information object</param>
        /// <param name="context">The context for the serialisation process.</param>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("resource", _resource);
        }

        #endregion



        // Public constructors
        // ===================
        #region Public constructors
        /// <summary>
        /// Constructs a new PdfResourceParseException instance.
        /// </summary>
        public PdfResourceParseException(PdfResourceReference resource) : this(resource, null) { }

        /// <summary>
        /// Constructs a new PdfResourceParseException instance.
        /// </summary>
        public PdfResourceParseException(PdfResourceReference resource, Exception innerException)
            : base("Information for this resource could not be parsed. See the inner exception for specifics on the parse failure.", innerException)
        {
            _resource = resource;
        }

        /// <summary>
        /// Constructs a new PdfResourceParseException instance out of a serialisation stream.
        /// </summary>
        /// <param name="info">The serialisation data</param>
        /// <param name="context">The streaming context for the serialisation process</param>
        public PdfResourceParseException(SerializationInfo info, StreamingContext context)
            : base(info, context) 
        {
            _resource = (PdfResourceReference)info.GetValue("resource", typeof(PdfResourceReference));
        }
        #endregion

    } // PdfResourceParseException class
}
